//
// Created by HP on 2022/1/3.
//

#ifndef VULKAN_TUTORIAL_LVE_WINDOW_H
#define VULKAN_TUTORIAL_LVE_WINDOW_H

#define GLFW_INCLUDE_VULKAN
#include "GLFW/glfw3.h"
#include <vulkan/vulkan_core.h>

// std
#include <string>

namespace lve {

    class LveWindow {
    public:
        LveWindow(int w, int h, std::string name);
        ~LveWindow();

        LveWindow(const LveWindow &) = delete;
        LveWindow &operator=(const LveWindow &) = delete;

        bool shouldClose() { return glfwWindowShouldClose(window); };
        [[nodiscard]] VkExtent2D getExtent() const { return { static_cast<uint32_t>(width), static_cast<uint32_t>(height) }; }
        void getCursorPos(double *xPos, double *yPos);
        [[nodiscard]] bool wasWindowResized() const { return framebufferResized; }
        void resetWindowResizedFlag() { framebufferResized = false; }
        [[nodiscard]] GLFWwindow* getGLFWwindow() const { return window; }
        void createWindowSurface(VkInstance instance, VkSurfaceKHR *surface);
    private:
        // GLFW 允许注册一个会在窗口大小变化时触发的回调函数
        static void framebufferResizedCallback(GLFWwindow *window, int width, int height);
        static void cursorEnterCallback(GLFWwindow* window, int entered);
        static void mouseButtonInputCallback(GLFWwindow* window, int button, int action, int mods);
        static void keyboardInputCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
        void initWindow();

        int width;
        int height;
        bool framebufferResized = false;
        bool isEnter = false;

        std::string windowName;
        GLFWwindow *window;
    };
}


#endif //VULKAN_TUTORIAL_LVE_WINDOW_H
